package com.javasm.crm.service.giftservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.criteria.GiftInfoCriteria;
import com.javasm.crm.domin.entity.gift.*;
import com.javasm.crm.mapper.giftmapper.GiftGoodMapper;
import com.javasm.crm.mapper.giftmapper.GoodsGiftMapper;
import com.javasm.crm.service.giftservice.GiftGoodService;
import com.javasm.crm.service.giftservice.GoodsGiftService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whl
 * @since 2021-07-12
 */
@Service
public class GoodsGiftServiceImpl extends ServiceImpl<GoodsGiftMapper, GoodsGift> implements GoodsGiftService {
	@Autowired
	GoodsGiftMapper goodsGiftMapper;

	@Override
	public PageResult<GoodsGiftVo> searchPageByCriteria(GiftInfoCriteria giftInfoCriteria) {
		Integer currentPage = giftInfoCriteria.getCurrentPage();
		Integer pageSize = giftInfoCriteria.getPageSize();

		if (StringUtils.isEmpty(currentPage)) {
			currentPage = 1;
		}
		if (StringUtils.isEmpty(pageSize)) {
			pageSize = 5;
		}
//        PageHelper.startPage(currentPage, pageSize);
		String name = giftInfoCriteria.getGiftName();
		//条件查询
		QueryWrapper<GoodsGiftVo> exampleQueryWrapper = new QueryWrapper<>();
//        LambdaQueryWrapper<StudentEntity> lambda = exampleQueryWrapper.lambda();
//
////        if (!StringUtils.isEmpty(name)) {
////            lambda.like(StudentEntity::getName, name);
////        }

		exampleQueryWrapper.eq("gg.deleted", 0);

		if (!StringUtils.isEmpty(giftInfoCriteria.getGoodName())) {
			exampleQueryWrapper.like("gg.good_name", giftInfoCriteria.getGoodName());
		}
		if (!StringUtils.isEmpty(giftInfoCriteria.getGoodModel())) {
			exampleQueryWrapper.like("gg.good_model", giftInfoCriteria.getGoodModel());
		}
		if (!StringUtils.isEmpty(giftInfoCriteria.getColorId())) {
			exampleQueryWrapper.eq("pc.color_id", giftInfoCriteria.getColorId());
		}
		if (!StringUtils.isEmpty(giftInfoCriteria.getBrandId())) {
			exampleQueryWrapper.eq("pb.brand_id", giftInfoCriteria.getBrandId());
		}
		if (!StringUtils.isEmpty(giftInfoCriteria.getTypeId())) {
			exampleQueryWrapper.eq("pt.type_id", giftInfoCriteria.getTypeId());
		}
		if (!StringUtils.isEmpty(giftInfoCriteria.getGoodCheckid())) {
			exampleQueryWrapper.eq("gc.gift_checkid", giftInfoCriteria.getGoodCheckid());
		}

		Page<GoodsGiftVo> examplePage = new Page<>(currentPage, pageSize);

		List<GoodsGiftVo> queryall = goodsGiftMapper.queryall(examplePage, exampleQueryWrapper);

		PageResult<GoodsGiftVo> studentEntityPageResult = new PageResult<>(examplePage.getTotal(), queryall);

		return new  PageResult<GoodsGiftVo>(examplePage.getTotal(),queryall);

	}

	@Override
	public List<GiftColor> findColor() {
		List<GiftColor> queryColor = goodsGiftMapper.queryColor();
		return queryColor;
	}
	@Override
	public List<GiftType> findType() {
		List<GiftType> queryType = goodsGiftMapper.queryType();
		return queryType;
	}
	@Override
	public List<GiftBrand> findBrand() {
		List<GiftBrand> queryBrand = goodsGiftMapper.queryBrand();
		return queryBrand;
	}

	@Override
	public List<GiftCheck> findCheck() {
		List<GiftCheck> queryCheck = goodsGiftMapper.queryCheck();
		return queryCheck;
	}

	@Override
	public int addGoodsGift(GoodsGift goodsGift) {
		return goodsGiftMapper.insert(goodsGift);
	}

	@Override
	public int editGoodsGift(GoodsGift goodsGift) {
		return goodsGiftMapper.updateById(goodsGift);
	}

	@Override
	public int deleteById(Serializable id) {
		return goodsGiftMapper.deleteById(id);
	}


}
